/**
 * 单例装饰器
 * @returns 类装饰器
 */
export function Singleton<T extends { new (...args: any[]): any }>(constructor: T) {
    let instance: T | null = null;

    // 保存原始构造函数
    const original = constructor;

    // 创建新的构造函数
    const newConstructor: any = function (...args: any[]) {
        if (!instance) {
            instance = new original(...args);
        }
        return instance;
    }

    // 复制原型链
    newConstructor.prototype = original.prototype;

    // 返回新的构造函数
    return newConstructor as T;
}

/**
 * 获取单例实例
 * @param constructor 构造函数
 * @returns 单例实例
 */
export function getInstance<T>(constructor: new () => T): T {
    return new (constructor as any)();
} 